package com.wocao.controller.uniapp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wocao.entity.ReqBody;
import com.wocao.entity.ResponseResult;
import com.wocao.entity.ZyRepair;
import com.wocao.service.ZyRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 报事报修页面
 */
@RestController
@CrossOrigin
@RequestMapping("/uni-app/repair")
public class RepairViewController {

    @Autowired
    private ZyRepairService repairService;

    /**
     * 提交评价+删除评论
     *
     * @param reqBody reqBody
     * @return return
     */
    @PutMapping("update")
    public ResponseResult evaluate(@RequestBody ReqBody reqBody) {
//       获取当前时间
        LocalDateTime now = LocalDateTime.now();

        ZyRepair repair = repairService.getOne(new QueryWrapper<ZyRepair>().eq("repair_num", reqBody.getRepairNum()));
        repair.setCompleteTime(now);
        repair.setRepairLike(reqBody.getRepairLike());
        repairService.updateById(repair);
        return ResponseResult.ok();
    }

    /**
     * 删除保修
     *
     * @param repairNum repairNum
     * @return return
     */
    @DeleteMapping("{repairNum}")
    public ResponseResult delete(@PathVariable String repairNum) {
        ZyRepair repair = repairService.getOne(new QueryWrapper<ZyRepair>().eq("repair_num", repairNum));
        repair.setDelFlag(1);
        repairService.updateById(repair);
        return ResponseResult.ok("");
    }

}
